package com.arsn.myf.system.controller;

import com.arsn.myf.common.util.result.Func;
import com.arsn.myf.common.util.result.R;
import com.arsn.myf.system.entity.Post;
import com.arsn.myf.system.service.PostService;
import com.arsn.myf.system.vo.PostVO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.wildfly.common.annotation.NotNull;

import java.util.Arrays;

/**
 * 岗位
 * @author zhongrj
 * @since 2022-07-10
 */
@RestController
@RequestMapping("/post")
@AllArgsConstructor
@Api(value = "岗位", tags = "岗位")
public class PostController {

    private final PostService postService;

    /**
     * 查询岗位的分页数据
     * @param page
     * @param post
     * @return
     */
    @GetMapping("/list")
    @ApiOperation(value = "查询岗位的分页数据")
    public R list(Page<Post> page, Post post){
        return R.data(postService.page(page,new QueryWrapper<>(post)));
    }


    /**
     * 自定义查询岗位的分页数据
     * @param page
     * @param post
     * @return
     */
    @GetMapping("/page")
    @ApiOperation(value = "自定义查询岗位的分页数据")
    public R page(Page<PostVO> page, PostVO post){
        return R.data(postService.selectPagePostList(page,post));
    }


    /**
     * 岗位详情信息
     * @param post
     * @return
     */
    @GetMapping("/detail")
    @ApiOperation(value = "岗位详情信息")
    public R detail(Post post){
        return R.data(postService.getOne(new QueryWrapper<>(post)));
    }


    /**
     * 岗位新增
     * @param post
     * @return
     */
    @PostMapping("/save")
    @ApiOperation(value = "岗位新增")
    public R save(@RequestBody Post post){
        return R.status(postService.save(post));
    }

    /**
     * 岗位修改
     * @param post
     * @return
     */
    @PostMapping("/update")
    @ApiOperation(value = "岗位修改")
    public R update(@RequestBody Post post){
        return R.status(postService.updateById(post));
    }


    /**
     * 删除,批量删除
     * @param ids
     * @return
     */
    @PostMapping("/remove")
    @ApiOperation(value = "删除,批量删除")
    public R remove(@NotNull String ids){
        return R.status(postService.removeByIds(Func.stringToLong(Arrays.asList(ids.split(",")))));
    }

    /**
     * 查询 岗位列表（不分页）
     * @param post 岗位对象参数
     * @return
     */
    @GetMapping("/getPostList")
    @ApiOperation(value = "查询 岗位列表（不分页）")
    public R getPostList(PostVO post){
        return R.data(postService.getPostList(post));
    }
}
